package mapEditor.view
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import mapEditor.events.MapEditorEvent;

	public class AssetClassView extends Sprite
	{
		private var _itemList:Array=[];
		
		public function AssetClassView()
		{
		}
		
		/**
		 *增加子项 
		 */		
		public function addItem(item:AssetClassListView):void
		{
			item.y=height;
			item.addEventListener(MapEditorEvent.MAP_ASSET_DOUBLE_CLICK, __onItemDoubleClick);
			addChild(item);
			_itemList.push(item);
		}
		
		/**
		 *清除所有子项 
		 */		
		public function clearAllItem():void
		{
			for(var i:int=0;i<_itemList.length;i++)
			{
				var item:AssetClassListView=_itemList[i] as AssetClassListView;
				item.removeEventListener(MapEditorEvent.MAP_ASSET_DOUBLE_CLICK, __onItemDoubleClick);
				if(item)
				{
					if(item.parent) item.parent.removeChild(item);
					item.dispose();
				}
				item=null;
			}
		}

		private function __onItemDoubleClick(evt:MapEditorEvent):void
		{
			dispatchEvent(new MapEditorEvent(MapEditorEvent.MAP_ASSET_DOUBLE_CLICK));
		}
		
		/**
		 *子项列表 
		 */		
		public function get itemList():Array
		{
			return _itemList;
		}

		/**
		 *子项列表 
		 */
		public function set itemList(value:Array):void
		{
			_itemList = value;
		}
		
		public function dispose():void
		{
			clearAllItem();
			_itemList=null;
			if(parent) parent.removeChild(this);
		}
	}
}